/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.dao.dept;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import edu.uwm.universitydb.framework.nontransactional.db.command.impl.NonTransactionalDBFetchCommandBase;
import edu.uwm.universitydb.model.Department;

/**
 * Command class to fetch all the departments <code>FetchDepartmentListCommand</type> here
 * 
 * @author Shyam Nair
 */
public class FetchDepartmentListCommand extends
    NonTransactionalDBFetchCommandBase<List<Department>>
{
    /** constant representing db column dno */
    private static final String COLUMN_DEPT_NUM = "dno";

    /** constant representing db column dname */
    private static final String COLUMN_DEPT_NAME = "name";

    /** constant representing db column main_office */
    private static final String COLUMN_MAIN_OFFICE = "main_office";

    /** query string */
    private static final String QUERY_SQL = "select " + COLUMN_DEPT_NUM + ", " + COLUMN_DEPT_NAME
        + ", " + COLUMN_MAIN_OFFICE + " from department";

    /*
     * (non-javadoc)
     * @see edu.uwm.cs757.framework.db.command.DataFetchCommand#processResult(java.sql.ResultSet)
     */
    @Override
    public List<Department> processResult(final ResultSet result) throws SQLException
    {
        final List<Department> deptList = new ArrayList<Department>();
        while (result.next())
        {
            final Integer deptNumber = result.getInt(COLUMN_DEPT_NUM);
            final String deptName = result.getString(COLUMN_DEPT_NAME);
            final Department dept = new Department(deptNumber, deptName);
            deptList.add(dept);
        }
        return deptList;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.cs757.framework.db.command.DBCommand#getSQL()
     */
    @Override
    public String getSQL()
    {
        return QUERY_SQL;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.cs757.framework.db.command.DBCommand#setParameters(java.sql.PreparedStatement)
     */
    @Override
    public void setParameters(final PreparedStatement pStmt) throws SQLException
    {
        // DO NOTHING as there are no parameters
    }

}

/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 9, 2014   Shyam Nair
 * File created
 * ----------------------------------------------------------------------------
 */